// pages/companyNewsDetail.js
var WxParse = require('../../wxParse/wxParse.js');
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    News:{}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var url = '/platform_api/newDetail';
    var params = {
      id: options.id
    };
    app.HttpPostSend(url, params, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      } else {
        var goods = res.data;
        goods.create_time = that.timestampToTime(goods.create_time * 1000);
        that.setData({
          News: goods
        })
        var article = goods.content;
        WxParse.wxParse('article', 'html', article, that, 5);
      }
    });  
  },

  timestampToTime: function (timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    var h = date.getHours() + ':';
    if (String(date.getMinutes()).length == 1) {
      var m = "0" + date.getMinutes() + ':';
    } else {
      m = date.getMinutes() + ':';
    }
    if (String(date.getSeconds()).length == 1) {
      var s = "0" + date.getSeconds() + ':';
    } else {
      s = date.getSeconds();
    }
    return Y + M + D + ' ' + h + m + s;
  },//转化后格式xxxx-xx-xx,

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  renderCarte: function (params) {
    const that = this
    // let 
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})